//
//  NWStatusRetweetView.swift
//  Weibo
//
//  Created by Northwan on 16/1/25.
//  Copyright © 2016年 Northwan. All rights reserved.
//

import UIKit
import SnapKit

class NWStatusRetweetView: UIView {
    
    var bottomConstraint:Constraint?
    
    var statusViewModel:NWStatusViewModel?{
        didSet{
            contentLabel.text = statusViewModel?.retweetText
            
            bottomConstraint?.uninstall()
            if let pic_urls = statusViewModel?.status?.retweeted_status?.pic_urls where pic_urls.count > 0{
                //设置图片数据
                photosView.hidden = false
                
                photosView.pic_urls = pic_urls
                
                snp_updateConstraints(closure: { (make) -> Void in
                   self.bottomConstraint = make.bottom.equalTo(photosView.snp_bottom).offset(NWStatusCellSubViewsMargin).constraint
                })
               
            }else{
                photosView.hidden = true
                snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraint = make.bottom.equalTo(contentLabel.snp_bottom).offset(NWStatusCellSubViewsMargin).constraint
                })
            }
            
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        addSubview(contentLabel)
        addSubview(photosView)
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(NWStatusCellSubViewsMargin)
            make.leading.equalTo(self).offset(NWStatusCellSubViewsMargin)
        }
        
        photosView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(contentLabel.snp_leading)
            make.top.equalTo(contentLabel.snp_bottom).offset(NWStatusCellSubViewsMargin)
        }
        
        snp_makeConstraints { (make) -> Void in
           bottomConstraint =   make.bottom.equalTo(photosView.snp_bottom).offset(NWStatusCellSubViewsMargin).constraint
        }
    }
    
    
    // MARK: - 懒加载
    private lazy var contentLabel:UILabel = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 15, maxWidth: SCREENW - 2 * NWStatusCellSubViewsMargin)
    
    private lazy var photosView:NWStatusPhotosView = {
        let view = NWStatusPhotosView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
}
